"""
    实现一个简单的神经网络-运用梯度下降
"""

import sys,os
sys.path.append(os.pardir)

import numpy as np
from common.functions import softmax_function_v2
from common.loss_functions import cross_entropy_error
from common.numerial_gradient import numerical_gradient

class simpleNet:
    def __init__(self):
        # 高斯分布 2 * 3 的 W
        np.random.seed(42)
        self.W = np.random.randn(2,3)

    def predict(self,x):
        return np.dot(x,self.W)

    def loss(self,x,t):
        z = self.predict(x)
        y = softmax_function_v2(z)
        loss = cross_entropy_error(y,t)

        return loss



if __name__ == '__main__':
    net = simpleNet()
    print(net.W)
    print(net.W.shape)
    x = np.array([0.6,0.9])
    predict_data = net.predict(x)
    print(predict_data)
    print(np.argmax(predict_data))
    t = np.array([0,0,1])
    print(net.loss(x, t))


    def f(W):
        return net.loss(x, t)

    dW = numerical_gradient(f,net.W)
    print(f"数值微分:{dW}")


